import { Prisma } from "@prisma/generated-client";

export async function page(
  model: Prisma.TransactionClient["user"],
  page: number,
  size: number,
  where: Prisma.UserWhereInput,
  orderBy?: Prisma.UserCountOrderByAggregateInput
): Promise<{
  data: Awaited<ReturnType<Prisma.TransactionClient["user"]["findMany"]>>;
  total: number;
}>;
export async function page(
  model: Prisma.TransactionClient["role"],
  page: number,
  size: number,
  where: Prisma.RoleWhereInput,
  orderBy?: Prisma.RoleCountOrderByAggregateInput
): Promise<{
  data: Awaited<ReturnType<Prisma.TransactionClient["role"]["findMany"]>>;
  total: number;
}>;
export async function page(
  model: any,
  page: number,
  size: number,
  where: any,
  orderBy?: any
): Promise<any> {
  if (!orderBy) {
    orderBy = {
      createdAt: "desc",
    };
  }

  const total = await model.count({ where });
  const data = await model.findMany({
    skip: (page - 1) * size, // 跳过 (页码 - 1) * 每页数量 的记录
    take: size, // 获取 pageSize 数量的记录
    where,
    orderBy,
  });

  return { data, total };
}
